import unittest
import requests
from parameterized import parameterized


class TestLogin(unittest.TestCase):
    data = [
        ('13800000002', '123456', 200, True, 10000, '操作成功'),
        ('13800002332', '123456', 200, False, 20001, '用户名或密码错误'),
        ('13800000002', '123abc', 200, False, 20001, '用户名或密码错误')
    ]

    @parameterized.expand(data)
    def test_login(self, x, y, status_code, success, code, msg):
        login_info = {
            "mobile": x,
            "password": y
        }

        # 发送请求
        url = "http://ihrm-test.itheima.net/api/sys/login"

        response = requests.post(url, json=login_info)

        self.assertEqual(status_code, response.status_code)
        self.assertEqual(success, response.json().get('success'))
        self.assertEqual(code, response.json().get('code'))
        self.assertIn(msg, response.json().get('message'))